package com.hopu.blb_erp.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.blb_erp.entity.Commodity;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.User;
import com.hopu.blb_erp.service.CommodityService;
import com.hopu.blb_erp.service.ICommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
<<<<<<< Updated upstream
 * @author A-Zhang
 * @since 2021-11-17
 */
@Api
@Controller
@RestController
public class CommodityController {
    @Autowired
    private CommodityService commodityService;
    @ApiOperation("分页")
    @GetMapping("/commoditys/{current}/{pageSize}")
    public ResponseEntity<PageEntity<Commodity>> listPage(@PathVariable("current") Integer current, @PathVariable("pageSize") Integer pageSize, String pName,String pEnterprise){
        PageEntity<Commodity> commodities = commodityService.listPage(current, pageSize,pName,pEnterprise);
        return ResponseEntity.ok(commodities);
    }

    @ApiOperation("修改用户状态")
    @PutMapping("/commodity/{id}/{state}")
    public ResponseEntity<String> update(@PathVariable("id") Integer id,@PathVariable("state") Boolean state){
        Commodity commodity = new Commodity();
        commodity.setId(id);
        if(state==true){
            commodity.setPStatus(true);
            commodityService.updateById(commodity);
            return ResponseEntity.ok("ok");
        }
        commodity.setPStatus(false);
        commodityService.updateById(commodity);
        return ResponseEntity.ok("no");
    }
    @PostMapping("/commodity")
    public ResponseEntity<String> add(@RequestBody Commodity commodity){

        commodity.setPAddtime(LocalDateTime.now());
        commodityService.saveOrUpdate(commodity);
        return ResponseEntity.ok("ok");
    }



}
